//
//  RHPlantStatusCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/11.
//

#import "RHPlantStatusCell.h"
#import "RHTools.h"

@interface RHPlantStatusCell()
@property (nonatomic, strong) QMUILabel *titleLab;

@property (nonatomic, strong) QMUILabel *plantCountLab;//电站数量

@property (nonatomic, strong) QMUILabel *deviceCountLab;//设备数量

@property (nonatomic, strong) QMUILabel *allCapacityLab;//总装机容量

@property (nonatomic, strong) QMUILabel *allPowerLab;//总装机功率

@property (nonatomic, strong) QMUILabel *capacityContentLab;//装机容量

@property (nonatomic, strong) QMUILabel *powerContentLab;//装机功率

@property (nonatomic, strong) QMUILabel *totalIncomeTitleLab;//累计收益
@property (nonatomic, strong) QMUILabel *totalIncomeLab;//累计收益
@property (nonatomic, strong) QMUILabel *yestodayIncomeLab;//昨日收益
@property (nonatomic, strong) QMUILabel *monthIncomeLab;//本月收益
@property (nonatomic, strong) QMUILabel *yearIncomeLab;//本年收益

@property (nonatomic, strong) QMUILabel *loadUseLab;//负载用电
@property (nonatomic, strong) QMUILabel *pvGenLab;//光伏发电
@property (nonatomic, strong) QMUILabel *batChgLab;//电池充电
@property (nonatomic, strong) QMUILabel *batDchgLab;//电池放电
@property (nonatomic, strong) QMUILabel *gridBuyLab;//电网买电
@property (nonatomic, strong) QMUILabel *gridSellLab;//电网卖电

@end
@implementation RHPlantStatusCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setupUI];
    }
    return self;
}

-(void)setDic:(NSDictionary *)dic
{
    _dic = dic;
 
    //电站数量
    self.plantCountLab.text = [NSString stringWithFormat:@"%ld",[dic[@"plantCount"] integerValue]];
    //设备数据
    self.deviceCountLab.text = [NSString stringWithFormat:@"%ld",[dic[@"deviceAmount"] integerValue]];
    
    //总装机容量
    NSString *capacityStr = [NSDecimalNumber decimalStringWithDoubleString:dic[@"installedCapacity"] nullStr:@"--"];
    self.allCapacityLab.text = [NSString stringWithFormat:@"%@ (kWh)",capacityStr];
    self.allCapacityLab.attributedText = [NSString attributeStringWithContent:self.allCapacityLab.text attriFont:kSYSTEMFONT(10) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.8) attriKey:@"(kWh)"];
    
    //总装机功率
    NSString *allPowerStr = [NSDecimalNumber decimalStringWithDoubleString:dic[@"accumulatedInstalledPower"] nullStr:@"--"];
    self.allPowerLab.text = [NSString stringWithFormat:@"%@ (kW)",allPowerStr];
    self.allPowerLab.attributedText = [NSString attributeStringWithContent:self.allPowerLab.text attriFont:kSYSTEMFONT(10) attriColor:kCOLOR_HEX_A(@"#3F4443", 0.8) attriKey:@"(kW)"];
    
    //收益
    NSString *totalIncomeStr = [NSDecimalNumber decimalStringWithDoubleString:dic[@"accumulatedRevenue"] nullStr:@"--"];
    self.totalIncomeLab.text = [NSString stringWithFormat:@"%@",totalIncomeStr];
   
    NSString *yestodayIncomeStr = [NSDecimalNumber decimalStringWithDoubleString:dic[@"yesterdayRevenue"] nullStr:@"--"];
    self.yestodayIncomeLab.text = [NSString stringWithFormat:@"%@",yestodayIncomeStr];
    
    NSString *monthIncomeStr = [NSDecimalNumber decimalStringWithDoubleString:dic[@"monthRevenue"] nullStr:@"--"];
    self.monthIncomeLab.text = [NSString stringWithFormat:@"%@",monthIncomeStr];
    
    NSString *yearIncomeStr = [NSDecimalNumber decimalStringWithDoubleString:dic[@"yearRevenue"] nullStr:@"--"];
    self.yearIncomeLab.text = [NSString stringWithFormat:@"%@",yearIncomeStr];
    
    
    //货币种类 0:人民币(CNY)  1:美元(USD) 2:欧元(EUR) 3:日元(JPY) 4:英镑(GBP)  5:澳元(AUD)
    NSString *currencyType = [RHTools getCurrentCurrencyType];
   
    self.totalIncomeTitleLab.text = [NSString stringWithFormat:@"%@(%@)",@"收益数据".rh_localized,currencyType];
    
    
    //在线状态
    QMUILabel *normalLab = [self.contentView viewWithTag:300];
    normalLab.text = [NSString stringWithFormat:@"%ld",[dic[@"normal"] integerValue]];
    
    QMUILabel *alarmLab = [self.contentView viewWithTag:301];
    alarmLab.text = [NSString stringWithFormat:@"%ld",[dic[@"alarm"] integerValue]];
    
    QMUILabel *faultLab = [self.contentView viewWithTag:302];
    faultLab.text = [NSString stringWithFormat:@"%ld",[dic[@"fault"] integerValue]];
    
    QMUILabel *offlineLab = [self.contentView viewWithTag:303];
    offlineLab.text = [NSString stringWithFormat:@"%ld",[dic[@"offline"] integerValue]];
}

-(void)setRunDic:(NSDictionary *)runDic
{
    _runDic = runDic;
    
    //负载用电
    NSString *todayUseValue = [NSString stringWithFormat:@"%@kWh",[NSDecimalNumber decimalStringWithDouble:[runDic[@"todayElectricity"] doubleValue]]];
    self.loadUseLab.attributedText = [NSString attributeStringWithContent:todayUseValue attriFont:kSYSTEMFONT(10) attriColor:kCOLOR_HEX_A(@"#132B88", 0.6) attriKey:@"kWh"];
    
    //光伏发电
    NSString *todayGenValue = [NSString stringWithFormat:@"%@ kWh",[NSDecimalNumber decimalStringWithDouble:[runDic[@"todayGeneration"] doubleValue]]];
    self.pvGenLab.attributedText = [NSString attributeStringWithContent:todayGenValue attriFont:kSYSTEMFONT(10) attriColor:kCOLOR_HEX_A(@"#132B88", 0.6) attriKey:@"kWh"];
    
    //电池充电
    NSString *batteryChgValue = [NSString stringWithFormat:@"%@ kWh",[NSDecimalNumber decimalStringWithDouble:[runDic[@"todayChg"] doubleValue]]];
    self.batChgLab.attributedText = [NSString attributeStringWithContent:batteryChgValue attriFont:kSYSTEMFONT(10) attriColor:kCOLOR_HEX_A(@"#132B88", 0.6) attriKey:@"kWh"];
    
    
    //电池放电
    NSString *batteryDchgValue = [NSString stringWithFormat:@"%@ kWh",[NSDecimalNumber decimalStringWithDouble:[runDic[@"todayDchg"] doubleValue]]];
    self.batDchgLab.attributedText = [NSString attributeStringWithContent:batteryDchgValue attriFont:kSYSTEMFONT(10) attriColor:kCOLOR_HEX_A(@"#132B88", 0.6) attriKey:@"kWh"];
    
    //电网买电
    NSString *gridBuyValue = [NSString stringWithFormat:@"%@ kWh",[NSDecimalNumber decimalStringWithDouble:[runDic[@"todayBuy"] doubleValue]]];
    self.gridBuyLab.attributedText = [NSString attributeStringWithContent:gridBuyValue attriFont:kSYSTEMFONT(10) attriColor:kCOLOR_HEX_A(@"#132B88", 0.6) attriKey:@"kWh"];
    
    //电网卖电
    NSString *gridSellValue = [NSString stringWithFormat:@"%@ kWh",[NSDecimalNumber decimalStringWithDouble:[runDic[@"todaySell"] doubleValue]]];
    self.gridSellLab.attributedText = [NSString attributeStringWithContent:gridSellValue attriFont:kSYSTEMFONT(10) attriColor:kCOLOR_HEX_A(@"#132B88", 0.6) attriKey:@"kWh"];
    
}

-(void)setupUI
{
    kWeakSelf;
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    UIView *bgView = kView;
    bgView.backgroundColor = [UIColor clearColor];
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];

    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(0);
        make.right.mas_offset(-0);
        make.bottom.mas_offset(-0);
    }];
    
    
    //----------------------- 资产数据
    UIView *assetView = [self assetView];
    [bgView addSubview:assetView];
    [assetView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.mas_offset(10);
    }];
    

    //------------------------- 收益数据 --------------------------
    UIView *earningView = [self earningView];
    [bgView addSubview:earningView];
    [earningView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(assetView.mas_bottom).offset(10);
      
    }];
    
 
    
    //-----------运行数据----------------
    
    UIView *rundataView = [self runView];;
    [bgView addSubview:rundataView];
    [rundataView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(earningView.mas_bottom).offset(10);
       
    }];

    
    //---------负载用电---------------
    UIView *loadView = [self loadAndPvViewWithIndex:1];
    [bgView addSubview:loadView];
    [loadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(rundataView.mas_bottom).offset(10);
        make.height.offset(50);
        
    }];
  
    
    //---------光伏发电---------------
    UIView *pvView = [self loadAndPvViewWithIndex:2];
    [bgView addSubview:pvView];
    [pvView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.equalTo(loadView.mas_bottom).offset(10);
        make.height.offset(50);
        
    }];
    
  
    //-------------电池-----------------------
    UIView *batteryView = [self itemViewWithIndex:1];
    [bgView addSubview:batteryView];
    [batteryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(pvView.mas_bottom).offset(10);
        make.width.offset((kUI_WINDOW_W-30-10)/2);
        make.bottom.mas_offset(0);//封底
    }];
  
    //-------------电网-----------
    UIView *gridView = [self itemViewWithIndex:2];
    [bgView addSubview:gridView];
    [gridView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(batteryView.mas_right).offset(10);
        make.right.mas_offset(-15);
        make.top.equalTo(batteryView);
    }];
}

//1.电站数量  2.设备数量
-(UIView*)plantDeviceItemViewWithIndex:(NSInteger)index
{
    kWeakSelf;
    UIView *bgView = kView;
    bgView.backgroundColor = index== 1?kCOLOR_HEX(@"#DAF7F0"):kCOLOR_HEX(@"#FFF6E9");
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    
    UIImageView *plantImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:index==1?@"kwt_home_plant_icon":@"kwt_home_device_icon"]];
    [bgView addSubview:plantImg];
    [plantImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.top.mas_offset(15);
        make.width.height.offset(20);
        
    }];
    UITapGestureRecognizer *plantTap = [[UITapGestureRecognizer alloc]init];
    [bgView addGestureRecognizer:plantTap];
    [plantTap.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
        if(weakSelf.plantAction){
            weakSelf.plantAction();
        }
    }];
    
    
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.text = index == 1?@"电站".rh_localized:@"设备".rh_localized;
    titleLab.font = kSYSTEMFONT(16);
    titleLab.textAlignment = NSTextAlignmentLeft;
    titleLab.textColor = [UIColor colorWithHexString:@"171A1D" alpha:0.6];
    titleLab.numberOfLines = 2;
    [bgView addSubview:titleLab];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(plantImg);
        make.left.equalTo(plantImg.mas_right).offset(10);
        make.width.lessThanOrEqualTo(@(80));
    }];
    
    QMUILabel *countLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(20) textColor:kCOLOR_HEX(@"3F4443") textAligment:NSTextAlignmentLeft];
    countLab.text = @"--";
    [bgView addSubview:countLab];
    
    [countLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(titleLab);
        make.left.equalTo(titleLab.mas_right).offset(3);
        make.right.mas_offset(-3);
    }];
    
    
    QMUILabel *seeLab = [QMUILabel labelWithFont:kSYSTEMFONT(11) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
    seeLab.text = @"查看".rh_localized;
    [bgView addSubview:seeLab];
    [seeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-10);
        make.left.mas_offset(15);
       
    }];
    
    UIImageView *arrow_plant = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_plant_arrow"]];
    arrow_plant.contentMode = UIViewContentModeScaleAspectFit;
    [bgView addSubview:arrow_plant];
    [arrow_plant mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(12);
        make.centerY.equalTo(seeLab);
        make.left.equalTo(seeLab.mas_right).offset(5);
    }];
    
    if (index == 1) {
        self.plantCountLab = countLab;
    }
    if (index == 2) {
        self.deviceCountLab = countLab;
    }
    
    return  bgView;
}

//资产数据
-(UIView *)assetView
{
    kWeakSelf;
    UIView *assetView = [[UIView alloc]init];
    assetView.backgroundColor = UIColor.whiteColor;
    assetView.layer.cornerRadius = 8;
    assetView.layer.borderColor = kCOLOR_HEX(@"#E3E6ED").CGColor;
    assetView.layer.borderWidth = 1;
    assetView.layer.masksToBounds = YES;
    
    QMUILabel *assetTitleLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
    assetTitleLab.text = @"资产数据".rh_localized;
    assetTitleLab.numberOfLines = 0;
    [assetView addSubview:assetTitleLab];
    [assetTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-10);
        make.top.mas_offset(15);
        
    }];
    //总装机容量 总装机功率
    UIView *capacityView = kView;
    capacityView.backgroundColor = kCOLOR_HEX(@"#F5EEFF");
    capacityView.layer.cornerRadius = 8;
    capacityView.layer.masksToBounds = YES;
    [assetView addSubview:capacityView];
    [capacityView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(assetTitleLab.mas_bottom).offset(15);
        make.right.mas_offset(-10);
        make.width.offset((kUI_WINDOW_W-30-30)/2.0);
        make.bottom.mas_offset(-15);
    }];
    
    UIImageView *capacityImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"capacity_icon"]];
    [capacityView addSubview:capacityImg];
    [capacityImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(15);
        make.width.height.offset(20);
    }];
    
    QMUILabel *capacityTitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(13) textColor:kCOLOR_HEX(@"#474B53") textAligment:NSTextAlignmentLeft];
    capacityTitleLab.text = @"总装机容量".rh_localized;
    capacityTitleLab.numberOfLines = 0;
    [capacityView addSubview:capacityTitleLab];
    [capacityTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(capacityImg);
        make.top.equalTo(capacityImg.mas_bottom).offset(15);
        make.right.mas_offset(-10);
    }];
    
    QMUILabel *capacityContentLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
    capacityContentLab.text = @"--";
    capacityContentLab.numberOfLines = 0;
    [capacityView addSubview:capacityContentLab];
    self.allCapacityLab = capacityContentLab;
    [capacityContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(capacityTitleLab);
        make.top.equalTo(capacityTitleLab.mas_bottom).offset(3);
        make.right.mas_offset(-10);
    }];
    
    QMUILabel *powerTitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(13) textColor:kCOLOR_HEX(@"#474B53") textAligment:NSTextAlignmentLeft];
    powerTitleLab.text = @"总装机功率".rh_localized;
    powerTitleLab.numberOfLines = 0;
    [capacityView addSubview:powerTitleLab];
    [powerTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(capacityImg);
        make.top.equalTo(capacityContentLab.mas_bottom).offset(15);
        make.right.mas_offset(-10);
    }];
    
    QMUILabel *powerContentLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
    powerContentLab.text = @"--";
    powerContentLab.numberOfLines = 0;
    [capacityView addSubview:powerContentLab];
    self.allPowerLab = powerContentLab;
    [powerContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(powerTitleLab);
        make.top.equalTo(powerTitleLab.mas_bottom).offset(3);
        make.right.mas_offset(-10);
        make.bottom.offset(-15);
    }];
    
    
    //-------------电站 数量--------------
    UIView *plantView = [self plantDeviceItemViewWithIndex:1];
    [assetView addSubview:plantView];
    [plantView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(10);
        make.top.equalTo(capacityView);
        make.right.equalTo(capacityView.mas_left).offset(-10);
        make.width.equalTo(capacityView);
    }];
    UITapGestureRecognizer *plantTap = [[UITapGestureRecognizer alloc]init];
    [plantView addGestureRecognizer:plantTap];
    [plantTap.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
        if(weakSelf.plantAction){
            weakSelf.plantAction();
        }
    }];
   
    //---------------设备数量-----------
    UIView *deviceView = [self plantDeviceItemViewWithIndex:2];
    [assetView addSubview:deviceView];
    [deviceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(plantView);
        make.top.equalTo(plantView.mas_bottom).offset(10);
        make.width.height.equalTo(plantView);
        make.bottom.equalTo(capacityView);
    }];
    
    UITapGestureRecognizer *deviceTap = [[UITapGestureRecognizer alloc]init];
    [deviceView addGestureRecognizer:deviceTap];
    [deviceTap.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
        if(weakSelf.deviceAction){
            weakSelf.deviceAction();
        }
    }];
    return  assetView;
}

//收益数据
-(UIView*)earningView
{
    UIView *earningView = kView;
    earningView.backgroundColor = UIColor.whiteColor;
    earningView.layer.cornerRadius = 8;
    earningView.layer.borderColor = kCOLOR_HEX(@"#E3E6ED").CGColor;
    earningView.layer.borderWidth = 1;
    earningView.layer.masksToBounds = YES;
    
    QMUILabel *earnTitleLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentLeft];
    earnTitleLab.text = @"收益数据".rh_localized;
    earnTitleLab.numberOfLines = 0;
    [earningView addSubview:earnTitleLab];
    [earnTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-10);
        make.top.mas_offset(15);
    }];
    
    UIImageView *earnIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_earn_icon"]];
    [earningView addSubview:earnIcon];
    [earnIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(earnTitleLab.mas_bottom).offset(15);
        make.width.height.offset(24);
    }];
    
    QMUILabel *earnTotalTitleLab = [QMUILabel labelWithFont:kSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#8B8D92") textAligment:NSTextAlignmentLeft];
    earnTotalTitleLab.text = @"累计收益".rh_localized;
    earnTotalTitleLab.numberOfLines = 0;
    [earningView addSubview:earnTotalTitleLab];
    self.totalIncomeTitleLab = earnTotalTitleLab;
    [earnTotalTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(earnIcon.mas_right).offset(3);
        make.centerY.equalTo(earnIcon);
    }];
    
    QMUILabel *earnTotalContentLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(18) textColor:kCOLOR_HEX(@"#05C79D") textAligment:NSTextAlignmentRight];
    earnTotalContentLab.text = @"--".rh_localized;
    earnTotalContentLab.numberOfLines = 0;
    [earningView addSubview:earnTotalContentLab];
    self.totalIncomeLab = earnTotalContentLab;
    [earnTotalContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(earnTotalTitleLab.mas_right).offset(3);
        make.centerY.equalTo(earnIcon);
        make.right.mas_offset(-25);
    }];
    
    
    __block CGFloat itemWidth = (kUI_WINDOW_W - 30)/3;
    NSArray *titles = @[@"昨日收益".rh_localized,@"本月收益".rh_localized,@"本年收益".rh_localized];
    [titles enumerateObjectsUsingBlock:^(NSString*  _Nonnull title, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *itemView = kView;
//        itemView.backgroundColor = kRandomColor;
        [earningView addSubview:itemView];
        [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(idx*itemWidth);
            make.top.equalTo(earnIcon.mas_bottom).offset(20);
            make.width.offset(itemWidth);
            if (idx == 0) {
                make.bottom.mas_offset(-20);
            }
        }];
        
        
        QMUILabel *titleLab = [QMUILabel labelWithFont:kSYSTEMFONT(13) textColor:kCOLOR_HEX(@"#8B8D92") textAligment:NSTextAlignmentLeft];
        titleLab.text = title;
        titleLab.numberOfLines = 0;
        [itemView addSubview:titleLab];
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.right.mas_offset(-3);
            make.top.mas_offset(0);
        }];
        
        QMUILabel *contentLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(18) textColor:kCOLOR_HEX(@"#05C79D") textAligment:NSTextAlignmentLeft];
        contentLab.text = @"--".rh_localized;
        contentLab.numberOfLines = 0;
        [itemView addSubview:contentLab];
        [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLab.mas_bottom).offset(5);
            make.left.right.equalTo(titleLab);
            make.bottom.mas_offset(0);
        }];
        if (idx == 0) {
            self.yestodayIncomeLab = contentLab;
        }
        if (idx == 1) {
            self.monthIncomeLab = contentLab;
        }
        if (idx == 2) {
            self.yearIncomeLab = contentLab;
        }
    }];
    
    
    return earningView;
}

//运行数据

-(UIView*)runView
{
    UIView *bgView = kView;
    
    UIView *rundataView = kView;
    rundataView.backgroundColor = UIColor.whiteColor;
    rundataView.layer.cornerRadius = 8;
    rundataView.layer.borderColor = kCOLOR_HEX(@"#E3E6ED").CGColor;
    rundataView.layer.borderWidth = 1;
    rundataView.layer.masksToBounds = YES;
    [bgView addSubview:rundataView];
    [rundataView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.top.mas_offset(10);
    }];
  
    QMUILabel *runTitleLab = [QMUILabel labelWithText:@"设备监控".rh_localized font:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#171A1D")];
    [rundataView addSubview:runTitleLab];
    [runTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_offset(15);
        make.height.offset(20);
    }];
  
    UIView *statusView = kView;
   
    [rundataView addSubview:statusView];
    NSMutableArray *itemArr3 = [NSMutableArray array];
    NSArray *titleArr3 = @[@"正常".rh_localized,@"告警".rh_localized,@"故障".rh_localized,@"离线".rh_localized];
    [titleArr3 enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *item_bgView3 = kView;
//        item_bgView3.backgroundColor = kRandomColor;
        [statusView addSubview:item_bgView3];
        [itemArr3 addObject:item_bgView3];
        [item_bgView3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.mas_offset(0);
        }];
        
        NSString *iconStr = [NSString stringWithFormat:@"plantStatus0%zd",idx+1];
        UIImageView *icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:iconStr]];
        [item_bgView3 addSubview:icon];
        [icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(0);
            make.width.height.offset(25);
            make.centerY.mas_offset(0);
        }];
        
        
        QMUILabel *titleLab = [[QMUILabel alloc]init];
        titleLab.text = titleArr3[idx];
        titleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
        titleLab.textAlignment = NSTextAlignmentLeft;
        titleLab.font = [UIFont systemFontOfSize:13];
        titleLab.numberOfLines = 2;
        titleLab.adjustsFontSizeToFitWidth = YES;
        titleLab.minimumScaleFactor = 0.8;
        [item_bgView3 addSubview:titleLab];
      
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(icon.mas_right).offset(5);
            make.right.mas_offset(0);
            make.bottom.mas_offset(-10);
        }];
        
        
        QMUILabel *contentLab = [[QMUILabel alloc]init];
        contentLab.tag = 300+idx;
        contentLab.text = @"--";
        contentLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.8];
        contentLab.textAlignment = NSTextAlignmentLeft;
        contentLab.font = [UIFont boldSystemFontOfSize:14];
        [item_bgView3 addSubview:contentLab];
       
        [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(icon.mas_right).offset(5);
            make.top.mas_offset(10);
        }];
    }];
    
    [statusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(runTitleLab.mas_bottom).offset(15);
        make.right.mas_offset(-15);
        make.height.offset(65);
        make.bottom.mas_offset(-15);
    }];
    
    [itemArr3 mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:80 leadSpacing:10 tailSpacing:0];
    
    return  rundataView;
}

//负载用电  光伏发电
-(UIView*)loadAndPvViewWithIndex:(NSInteger)index
{
    UIView *bgView = kView;
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 8;
    bgView.layer.borderColor = kCOLOR_HEX(@"#E3E6ED").CGColor;
    bgView.layer.borderWidth = 1;
    bgView.layer.masksToBounds = YES;
  
    UIImageView *icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:index==1?@"home_doday_load":@"home_doday_pv"]];
    [bgView addSubview:icon];
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_offset(0);
        make.left.mas_offset(15);
        make.width.height.offset(30);
    }];
  
    QMUILabel *titleLab = [QMUILabel labelWithFont:kSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#474B53") textAligment:NSTextAlignmentLeft];
    titleLab.text = index==1?@"负载用电".rh_localized:@"光伏发电".rh_localized;
    [bgView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_offset(0);
        make.left.equalTo(icon.mas_right).offset(5);
    }];
    
    QMUILabel *contentLab = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentRight];
    contentLab.text = @"--";
    [bgView addSubview:contentLab];
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_offset(0);
        make.left.equalTo(titleLab.mas_right).offset(5);
        make.right.mas_offset(-15);
    }];
    
    if (index == 1) {
        self.loadUseLab = contentLab;
    }
    if (index == 2) {
        self.pvGenLab = contentLab;
    }
    return bgView;
}

//电池  电网
-(UIView*)itemViewWithIndex:(NSInteger)index
{
    UIView *bgView = kView;
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 8;
    bgView.layer.borderColor = kCOLOR_HEX(@"#E3E6ED").CGColor;
    bgView.layer.borderWidth = 1;
    bgView.layer.masksToBounds = YES;
    
    UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:index==1?@"home_doday_battery":@"home_doday_grid"]];
    [bgView addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(30);
        make.left.mas_offset(10);
        make.top.mas_offset(10);
    }];
    
    
    QMUILabel *titleLab = [QMUILabel labelWithFont:kSYSTEMFONT(14) textColor:kCOLOR_HEX(@"#474B53") textAligment:NSTextAlignmentLeft];
    titleLab.numberOfLines = 2;
    titleLab.text = index==1?@"电池".rh_localized:@"电网".rh_localized;
    [bgView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(img.mas_right).offset(5);
        make.centerY.equalTo(img);
        make.right.mas_offset(-5);
    }];
    
    QMUILabel *titleLab1 = [QMUILabel labelWithFont:kSYSTEMFONT(12) textColor:kCOLOR_HEX(@"#8B8D92") textAligment:NSTextAlignmentLeft];
    titleLab1.numberOfLines = 2;
    titleLab1.text = index==1?@"充电".rh_localized:@"买电".rh_localized;
    [bgView addSubview:titleLab1];
    [titleLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(img.mas_bottom).offset(15);
    }];
    
    QMUILabel *contentLab1 = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentRight];
    contentLab1.text = @"--";
    [bgView addSubview:contentLab1];
    [contentLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab1.mas_right).offset(8);
        make.right.mas_offset(-15);
        make.centerY.equalTo(titleLab1);
    }];
    
    QMUILabel *titleLab2 = [QMUILabel labelWithFont:kSYSTEMFONT(12) textColor:kCOLOR_HEX(@"#8B8D92") textAligment:NSTextAlignmentLeft];
    titleLab2.numberOfLines = 2;
    titleLab2.text = index==1?@"放电".rh_localized:@"卖电".rh_localized;
    [bgView addSubview:titleLab2];
    [titleLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.equalTo(contentLab1.mas_bottom).offset(10);
        make.bottom.mas_offset(-15);
    }];
    
    QMUILabel *contentLab2 = [QMUILabel labelWithFont:kBOLDSYSTEMFONT(16) textColor:kCOLOR_HEX(@"#303133") textAligment:NSTextAlignmentRight];
    contentLab2.text = @"--";
    [bgView addSubview:contentLab2];
    [contentLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab2.mas_right).offset(8);
        make.right.mas_offset(-15);
        make.centerY.equalTo(titleLab2);
    }];
   
    if (index == 1) {
        self.batChgLab = contentLab1;
        self.batDchgLab = contentLab2;
    }
    if (index == 2) {
        self.gridBuyLab = contentLab1;
        self.gridSellLab = contentLab2;
    }
    return bgView;
}


@end
